package com.jeesite.modules.gallery.service;

import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.gallery.entity.Gallery;
import com.jeesite.modules.gallery.dao.GalleryDao;
import com.jeesite.modules.file.utils.FileUploadUtils;

/**
 * galleryService
 * @author LaVenderGong
 * @version 2025-08-23
 */
@Service
public class GalleryService extends CrudService<GalleryDao, Gallery> {

	/**
	 * 获取单条数据
	 * @param gallery
	 * @return
	 */
	@Override
	public Gallery get(Gallery gallery) {
		return super.get(gallery);
	}

	/**
	 * 查询分页数据
	 * @param gallery 查询条件
	 * @param gallery page 分页对象
	 * @return
	 */
	@Override
	public Page<Gallery> findPage(Gallery gallery) {
		return super.findPage(gallery);
	}

	/**
	 * 查询列表数据
	 * @param gallery
	 * @return
	 */
	@Override
	public List<Gallery> findList(Gallery gallery) {
		return super.findList(gallery);
	}

	/**
	 * 保存数据（插入或更新）
	 * @param gallery
	 */
	@Override
	@Transactional
	public void save(Gallery gallery) {
		super.save(gallery);
		// 保存上传图片
		FileUploadUtils.saveFileUpload(gallery, gallery.getId(), "gallery_image");
	}

	/**
	 * 更新状态
	 * @param gallery
	 */
	@Override
	@Transactional
	public void updateStatus(Gallery gallery) {
		super.updateStatus(gallery);
	}

	/**
	 * 删除数据
	 * @param gallery
	 */
	@Override
	@Transactional
	public void delete(Gallery gallery) {
		super.delete(gallery);
	}

    public void updateUrl(Gallery gallery) {
		Gallery entity = get(gallery.getTid());
		if (entity != null) {
			entity.setUrl(gallery.getUrl());
			super.save(entity);
		}
    }
}
